package vn.edu.saigontech.ncms.web.offering;

import vn.edu.saigontech.ncms.util.Checker;
import vn.edu.saigontech.ncms.web.AbstractValidator;

@SuppressWarnings("serial")
public class ValidateAttendanceReportAction extends AbstractValidator {
	private String fromWeek;
	private String toWeek;
	private int maxWeek;
	
	@Override
	public String check() {
		if(Checker.isEmpty(this.fromWeek)) {
			this.sendKeyError("validator.required", "fromWeek");
		}
		if(!Checker.isInteger(this.fromWeek)) {
			this.sendKeyError("validator.invalid", "fromWeek");
		}
		Integer fromWeek = Integer.parseInt(this.fromWeek);
		if(fromWeek < 1) {
			this.sendKeyError("validator.greaterOrEqual", "fromWeek", "1");
		}
		if(fromWeek > maxWeek) {
			this.sendKeyError("validator.lessOrEqual", "fromWeek", maxWeek+"");
		}
		if(Checker.isEmpty(this.toWeek)) {
			this.sendKeyError("validator.required", "toWeek");
		}
		if(!Checker.isInteger(this.toWeek)) {
			this.sendKeyError("validator.invalid", "toWeek");
		}
		Integer toWeek = Integer.parseInt(this.toWeek);
		if(toWeek < 1) {
			this.sendKeyError("validator.greaterOrEqual", "toWeek", "1");
		}
		if(toWeek > maxWeek) {
			this.sendKeyError("validator.lessOrEqual", "toWeek", maxWeek+"");
		}
		if(fromWeek > toWeek)
			this.sendKeyError("validator.lessOrEqual", "fromWeek", "toWeek");
		return this.toSuccess();
	}

	public String getFromWeek() {
		return fromWeek;
	}

	public void setFromWeek(String fromWeek) {
		this.fromWeek = fromWeek;
	}

	public String getToWeek() {
		return toWeek;
	}

	public void setToWeek(String toWeek) {
		this.toWeek = toWeek;
	}

	public int getMaxWeek() {
		return maxWeek;
	}

	public void setMaxWeek(int maxWeek) {
		this.maxWeek = maxWeek;
	}
}
